<style type="text/css">

.act {
	margin: 0 0.5em;
	display: inline-block;
	width: 2em;
	height: 1.5em;
	padding-top: 0.5em;
	font-size: 1.5em;
	background-color: #00769D;
	font-weight: bold;
	color: #fff;
	border: 1px solid #00769D;
	text-align: center;
}
.noact {
	margin: 0 0.5em;
	display: inline-block;
	width: 2em;
	height: 1.5em;
	padding-top: 0.5em5
	font-size: 1.5em;
	background-color: #fff;
	font-weight: bold;
	border: 1px solid #00769D;
	text-align: center;
}
.noact a{
	color: #00769D !important;
}
</style>
<?php
// defined('ACC',true)||exit('ACC EXIT');
class PageTool{
	protected $total;//总条数
	protected $prepage;//每页显示的条数
	protected $page;//当前页面
	protected $pageshow;//显示多少页
	public function __construct($total,$prepage=8,$page=1,$pageshow=5){
		$this->total=$total;
		$this->prepage=$prepage;
		$this->page=$page;
		$this->pageshow=$pageshow;
	}
	public function show(){
		$parse=parse_url($_SERVER['REQUEST_URI']);
		$url=$parse['path'];
		$parse['query']=isset($parse['query'])?$parse['query']:'';
		parse_str($parse['query'],$query);
		$page=isset($query['page'])?$query['page']:$this->page;
		unset($query['page']);
		$str=http_build_query($query);
		if (empty($query)) {
			$url.='?';
		}else{
			$url.='?'.$str.'&';
		}
		$cnt=ceil($this->total/$this->prepage);
		if ($page>$cnt||$page<1) {
			$page=1;
		}
		$nav=array();
		$nav[0]="<span class='act'>&nbsp;".$page."&nbsp;</span>";
		for ($left=$page-1,$right=$page+1; ($left>=1||$right<=$cnt)&&count($nav)<$this->pageshow;) { 
			if ($left>=1) {
				array_unshift($nav,"<span class='noact'>&nbsp;<a href='".$url."page=".$left."'>".$left."</a>&nbsp;</span>");
				$left-=1;
			}
			if ($right<=$cnt) {
				array_push($nav,"<span class='noact'>&nbsp;<a href='".$url."page=".$right."'>".$right."</a>&nbsp;</span>");
				$right+=1;
			}
			
			
		}
		return implode('', $nav);

	}
}